package cn.edu.java.stream.特殊流;

import java.util.stream.LongStream;

public class LongStreamDemo {
    public static void main(String[] args) {
        // 创建 LongStream 流
        LongStream stream = LongStream.rangeClosed(1, 10);

        // 求和
        long sum = stream.sum();
        System.out.println("Sum: " + sum);

        // 求平均值
        double average = LongStream.of(1, 2, 3, 4, 5)
                .average()
                .orElse(0);
        System.out.println("Average: " + average);

        // 找到最大值
        long max = LongStream.of(1, 2, 3, 4, 5)
                .max()
                .orElse(0);
        System.out.println("Max: " + max);

        // 过滤偶数并打印
        LongStream.of(1, 2, 3, 4, 5)
                .filter(n -> n % 2 == 0)
                .forEach(System.out::println);
    }
}

